using System;
using System.Collections.Generic;
using Needle.Bus.Messages;

namespace Needle.Bus.Engine
{
    /// <summary>
    /// Defines a message source
    /// </summary>
    public interface ISource : IEngineComponent, IHasCount
    {

        /// <summary>
        /// Dequeues a message, returns false if no message is available, 
        /// This method never throws.
        /// </summary>
        bool TryDequeue(out IMessage message);

        /// <summary>
        /// Dequeues a number of messages, returns false if no messages are  
        /// available. This method never throws and can return fewer messages 
        /// than requested.
        /// </summary>
        bool TryDequeue(int maxCount, out IList<IMessage> messages);

        /// <summary>
        /// Dequeues a message.
        /// This method blocks until a message is available.
        /// </summary>
        IMessage Dequeue();

        /// <summary>
        /// Dequeues a message or blocks until one is available.
        /// This method throws if no message is available after the wait 
        /// period expires.
        /// </summary>
        IMessage Dequeue(TimeSpan wait);

        /// <summary>
        /// Dequeues the exact number of messages or blocks until the requested 
        /// number is available. This method throws if not enough messages are   
        /// available after the wait period expires.
        /// </summary>
        IList<IMessage> Dequeue(TimeSpan wait, int count);

    }
}
